package com.admin.action.library_page_action;

import com.admin.Action;
import com.pojo.AdminBean;
import com.utils.DateHelper;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class AdminMainAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        PrintWriter out=response.getWriter();
        System.out.println(session.getAttribute("adminInfo"));
        AdminBean adminAllInfo= (AdminBean) session.getAttribute("adminInfo");
        String startdate= adminAllInfo.getCreateTime();

        DateHelper dateHelper = new DateHelper();
        int day=0;
        try {
           day= dateHelper.daysBetween(startdate);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        System.out.println("时间爱你："+startdate);
//        System.out.println(day);
        String adminLevel=null;
        long level=adminAllInfo.getAdminLevel();
        if(level==1){
             adminLevel="普通管理员";
        }else if(level==2){
            adminLevel="超级管理员";
        }

        String str1 = "[{\"adminName\":\""+adminAllInfo.getAdminName()+"\",\"dateNowStr\":\""+day+
                "\",\"adminLevel\":\""+adminLevel+"\"}]";
        out.print(str1);

    }
}
